/**
	韩飞 列表设定信息
**/
var _currentOrgId = null;
var _currentDeptId = null;
var _currentPosId = null;
var _currentRoleId = null;
var _activeNode = null;
var _orgInfoCache = []; //记录读取过的ORG对象
var _noPos = false;
//树的左键  (获取各种可以的值)
function SPTree_clickNode($node, $nameDom, $fireEvent) {
	
    _noPos = false;
    $nameDom.style.color = "red";
    _activeNode = $node;
    _currentDeptId = null;
    _currentPosId = null;
    _currentRoleId = null;
    _currentOrgId = null;
    if ($node.url=="O") { //组织机构
      _currentOrgId = _activeNode.key;
    } else if ($node.url=="D") { //部门
      _currentDeptId = _activeNode.key;
      _currentOrgId = SPTree.getParent(_currentDeptId).key;
    } else if ($node.url=="P") { //岗位
      _currentPosId = _activeNode.key;
      _currentDeptId = SPTree.getParent(_currentPosId).key;
      _currentOrgId = SPTree.getParent(_currentDeptId).key
    } else if ($node.url=="L") { //无岗位员工
      _noPos = true;
    } else {
    }
    if($node.key!="ROOT"){
	    var spid = $node.key;
	    var depid = SPTree.getParent($node.key).key;
	    reloadLister(spid,depid);
    }else{
    }
}
function SPTree_clickNodeChange($node, $nameDom) {
   $nameDom.style.color = "black";
}
//外部接口open方法
function SPTree_nodeOpen($key) {
	SPTree.openNodeOne($key);
}
/** 树加载完毕 */
function SPTree_loaded() {
	if (_activeNode==null) {
		SPTree.clickByIndex(0); //这里有问题
		SPTree_nodeOpen("ROOT");//调用接口open方法实现只展开一个节点
	} else {
		var d = SPTree.getDom(_activeNode.key);
		if (d==null) { //节点被删除了
			SPTree.clickByIndex(1);
		} else {
			d = SPTree.getName(_activeNode.key);
			if (d.style.color!="red") { //被重载了
				SPTree.clickNode(_activeNode.key);
			}
		}
	}
}
//全局审批和部门标识
var appid,depmentid;
//重新读取设定表信息
function reloadLister(spid,depid) {
	var model = SPTree.getNodeModel(spid);
    if(SPTree.getNodeModel(spid).url=="D"){
    	appid = spid;
    	depmentid = depid;
    	//刷新右侧页面
    	document.all["inner"].src = _c + "/docolumn.action?operate=sel&appid="+appid+"&depid="+depid;
    	
    	//__get("domFilterDesc").innerHTML = SPTree.getNodeModel(spid).name+"：";
    }else{
    	appid = "";
    	depmentid ="";
    	//刷新右侧页面
    	document.all["inner"].src = _c + "/docolumn.action?operate=sel";
    	//__get("domFilterDesc").innerHTML = "";
    	//$("#jsonTbo").children().remove();
    	//$("#jsonTbo").append("<tr align='center'><td colspan='3'>请选择对应的行政审批项目</td></tr>");
    }
}

//选中不同的表查询字段信息
function showOnCheck(tabeninfo){
	$("#jsonTbo").children().remove();
	comdwr.getRowDataInfo(tabeninfo,function(list){
	  	if(list.length){
			for(var i=0;i<list.length;i++){
				var html = "<tr align='center' style='cursor: hand' onmouseover=\"this.style.backgroundColor='#EEF7FD';\" onmouseout=\"this.style.backgroundColor='';\"";
				html += " onclick=\"_clickRowEvent('"+list[i].id+"','"+list[i].fielden+"','"+list[i].fieldtype+"')\" >";
				html += "<td>"+list[i].fielden+"<input type='hidden' value='"+list[i].id+"' name='fieldid'></td>";
				html += "<td>"+list[i].fieldcn+"</td>";
				html += "<td>"+list[i].fieldtype+"</td>";
				html += "<td><span class='RoleSpan' style='color: green;' onclick='doCreaterow(\""+tabeninfo+"\",\""+list[i].fieldcn+"\",\""+list[i].fielden+"\",\""+list[i].fieldid+"\")'"+
				 		" title='添加' onmouseout=\"doMsOut('green')\" onmouseover=\"doMsOver()\">添加</span></td>";
				html += "</tr>";
				$("#jsonTbo").append(html);
			}
		}
	});
}

//点击表 查询对应表的字段信息
function onselect(obj,tabeninfo,tabid){
	$(".ondivjpg").bind("mouseout",function(){onmouseoverout(this);});
	$(".ondivjpg").children("span").css("font-weight","");
	$(".ondivjpg").removeClass("ondivjpg");
	$(obj).addClass("ondivjpg");
	$(obj).children("span").css("font-weight","bold");
	$(".ondivjpg").unbind("mouseout").removeAttr("onmouseout");
	
	//选择不同的表进行查询
	document.forms[0].taben.value = tabeninfo;
	showOnCheck(tabeninfo);
}
function onmouseoverobj(obj){
	$(obj).addClass("ondivjpg");
	$(obj).children("span").css("font-weight","bold");
}
function onmouseoverout(obj){
	$(obj).removeClass("ondivjpg");
	$(obj).children("span").css("font-weight","");
}
var fiecn; //方便获取 汉字名称
//弹出列表设定页面
function doCreaterow(tab,fcn,fen,fid){
	fiecn = fcn;
	var app = document.all["appid"].value;
	var dep = document.all["depid"].value;
	var url = _c + "/docolumn.action?operate=row&appid="+app+"&taben="+tab+"&fielden="+fen+"&fieldid="+fid+"&depid="+dep;
	doQueryMess(url,"","300","200");
}
//对应在父页创建列表设定元素
function cloneRowTab(app,rid,rod){
	//生成元素
	var html = "<table border='1' cellpadding='0' cellspacing='0' class='small_table' id='rt"+rid+"'>"
		+"<tr align='center'><th align='center'><div class='choosed2' ><a title='"+fiecn+"' href='#' onclick='removeRow(\""+app+"\",\""+rid+"\",\"rt"+rid+"\")'>"+fiecn+"<B></B></a></div></th></tr>"
		+"<tr align='center'><td height='15'>排序："+rod+"<input type='hidden' value='"+rod+"' name='roworderson'><input type='hidden' value='"+app+"' name='appidson'><input type='hidden' value='"+rid+"' name='rowidson'></td></tr>"
		+"</table>";
	//查找对应顺序
	var roworder = document.all.roworderson;
	var parentid;
	if(roworder && roworder.length){
		for(var i=0;i<roworder.length;i++){
			if((roworder[i].value-0) > (rod-0)){
				parentid = roworder[i].parentNode.parentNode.parentNode.parentNode.id;
				$("#"+parentid).before(html);
				break;
			}else{
				if(i==(roworder.length-1)){
					parentid = roworder[i].parentNode.parentNode.parentNode.parentNode.id;
					$("#"+parentid).after(html);
					break;
				}
			}
		}
		
	}else if(roworder){
		parentid = roworder.parentNode.parentNode.parentNode.parentNode.id;
		if((roworder.value-0) > (rod-0)){
			$("#"+parentid).before(html);
		}else{
			$("#"+parentid).after(html);
		}
	}else{
		$("#rowtab").empty();
		$("#rowtab").append(html);
	}
	//$("p").parent()
}
//删除列表设定信息
function removeRow(appcode,rowid,moveid){
	if(confirm("确认删除信息？")){
		comdwr.deleteRowset(appcode,rowid,function(bos){
			if(bos){
				$("#"+moveid).remove();
			}else{
				_alert('删除失败');
			}
		});
	}
}
